var ns,toast;
var app = new Vue({
    el: '#app',
    data: {
      form:{
        SettlementAmount:0, //结算金额(除去手续费)
        WithdrawalMoney:0, //提现金额
        offlineWithdrawalMoney:0, //线下申请金额
      },
      box:{
        WithdrawalMoney:0, //提现金额
        W_Type:1, //线上结算
        W_UserName:'', //姓名
        W_Phone:'', //电话
        W_IDCard:'', //身份证
        W_Note:'', //提现备注
        W_Bank:'', //开户行
        W_BankNumber:'', //开户行账号
        W_BankName:'' //开户行姓名
      },
      setBalance:{
        BusinessSettlementID:0,//结算表ID
        Approve_User_By:'',//批准用户
        Approve_Time:'', //批准时间
        Approve_Remark:'',//批准备注
        Approve_Status:0,//批准状态
        Transfer_Amount:0, //转账金额
        OnLine_Transfer_Amount:0,//线上转账金额
        OnlineRuleID:1,//线上申请规则ID
        OnlineConvertRate:0,//线上申请手续费比例
        OnlineShouXuFei:0,
        OffLine_Transfer_Amount:0,//线下转账金额
        OfflineRuleID:2, //线下申请规则ID
        OfflineConverRate:0,//线下申请手续费比例
      }
    },
methods:{
    open_application:function(){
      var that = this;
      var pname = that.box.W_UserName.replace(/[^A-Za-z0-9\u4e00-\u9fa5]/g,'');
      if(that.box.W_UserName==""){
        api.toast({
            msg: '填写姓名',
            duration: 2000,
            location: 'bottom'
        });
        return;
      }
      if(that.box.W_UserName != pname){
      api.toast({
          msg: '格式输入有误',
          duration: 2000,
          location: 'bottom'
      });
      that.box.W_UserName='';
      return;
    }
    if(that.form.WithdrawalMoney<=0){
      api.toast({
          msg: '没有提现金额',
          duration: 2000,
          location: 'bottom'
      });
      return;
    }
    if(that.box.W_Phone==""){
      api.toast({
          msg: '手机号码是空的',
          duration: 2000,
          location: 'bottom'
      });
      return;
    }
    //电话号码只能是11位
    // alert(that.box.payeePhone.length);
    if(that.box.W_Phone.length != 11){
       pnum : that.box.W_Phone,
      api.toast({
          msg: '电话号码格式错误',
          duration: 2000,
          location: 'bottom'
      });
      return;
    }
    if(that.box.W_IDCard==""){
      api.toast({
          msg: '还有身份证号哟',
          duration: 2000,
          location: 'bottom'
      });
      return;
    }
    //身份证号码只能是18位
    if(that.box.W_IDCard.length != 18){
      api.toast({
          msg: '错误的身份证号',
          duration: 2000,
          location: 'bottom'
      });
      return;
    }
    //alert(JSON.stringify(that.setBalance));
    var options={};
    options.WithdrawalMoney=that.form.WithdrawalMoney;
    options.SettlementAmount= that.form.SettlementAmount;
    options.W_Type = that.box.W_Type;
    options.W_UserName = that.box.W_UserName;
    options.W_Phone = that.box.W_Phone;
    options.W_IDCard = that.box.W_IDCard;
    options.W_Note = that.box.W_Note;
    options.W_Bank = that.box.W_Bank;
    options.W_BankNumber = that.box.W_BankNumber;
    options.W_BankName = that.box.W_BankName;
    options.OffLine_WithdrowMonety=that.form.offlineWithdrawalMoney;
    options.setBalance=that.setBalance;
    options.action = 'savemallbusinesssettlementlist';
    ns.post(options, function(succeed, data, err) {
        // toast.hide();
        if (succeed) {
            that.box.payeeName = '';
            that.box.payeePhone = '';
            that.box.idNumber = '';
            that.box.remarks = '';
            that.box.bank = '';
            that.box.bankNumber = '';
            that.box.bankName = '';
            // app.set_default();
            api.toast({
                msg: '提交成功',
                duration: 1000,
                location: 'bottom'
            });
            api.sendEvent({
                name: 'tixian'
            });
            setTimeout(function() {
              api.closeWin();
            }, 2000);

        } else if (err) {
            api.toast({
                msg: err,
                duration: 2000,
                location: 'bottom'
            });
        }
    });
    },
  }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
     //alert(api.pageParam.setBalance);
     app.form.WithdrawalMoney=api.pageParam.Amount;
     app.form.SettlementAmount=api.pageParam.cashMoney;
     app.form.offlineWithdrawalMoney=api.pageParam.offline_Amount;
     app.setBalance=api.pageParam.setBalance;
};
